package com.liu.common.service.impl;

import com.liu.common.service.GetTokenService;
import org.springframework.stereotype.Service;
import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;

import javax.servlet.http.HttpServletRequest;

@Service
public class GetTokenServiceImpl implements GetTokenService {
    @Override
    public String getToken() {
        ServletRequestAttributes attributes = (ServletRequestAttributes) RequestContextHolder.getRequestAttributes();
        HttpServletRequest request = null;
        String token = null;
        if (attributes != null) {
            request = attributes.getRequest();
            token = request.getHeader("token");
        }
        return token;
    }
}
